﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Hosting.Class;

namespace Hosting.Webform
{
    public partial class AddAdmin : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void getMessage(string message)
        {
            divBigNotification.Attributes["class"] = "notification attention png_bg";
            divBigNotification.Attributes["style"] = "display:block;";
            divNotification.InnerHtml = message;
        }

        /* addValid() method return:
         * 1: Validation is successful!
         * 10: Username input is null or not have value
         * 11: Username is less than 5 character
         * 12: Username is bigger than 50 character
         * 13: Username is have an special character, Valid: [a-zA-Z0-9]
         * 14: Username is existed
         * 20: Password input is null or not have value
         * 21: Password is less than 5 character
         * 22: Password is bigger than 100 character
         * 23: Password is not valid, Valid: [a-zA-Z0-9@!#$\'%^&*`~]
         * 24: Password and repassword is not match
         * 30: Email is not valid
         * 31: Email is too big
         * 40: Phone is null or not have value
         * 41: Phone must be number
         * 42: Phone is less than 10 character
         * 43: Phone is bigger than 15 character
         * 50: Address is null or not have value
         * 51: Address is too long
         */

        protected void Create_Click(object sender, EventArgs e)
        {
            Users users = new Users();
            int isValid = users.addValid(txtUsername.Value, txtPassword.Value, txtRePassword.Value, txtPhone.Value, txtEmail.Value, txtAddress.Value);
            if (isValid == 1)
            {

                int isInsert = users.Add(txtUsername.Value, txtPassword.Value, txtPhone.Value, txtEmail.Value, txtAddress.Value);
                if (isInsert == 0)
                {
                    getMessage("Data inserts successfully!");
                    divBigNotification.Attributes["class"] = "notification success png_bg";
                }
                else
                {
                    getMessage("There is an error!");
                    divBigNotification.Attributes["class"] = "notification error png_bg";
                }

            }
            else if (isValid == 14)
            {
                getMessage("Username is existed!");
            }
            else
            {
                getMessage("Data is not Valid!");
            }

        }

        protected void Reset_Click(object sender, EventArgs e)
        {
            txtUsername.Value = "";
            txtPassword.Value = "";
            txtRePassword.Value = "";
            txtPhone.Value = "";
            txtEmail.Value = "";
            txtAddress.Value = "";
        }

    }
}